<template>
    <div>
        <router-link v-show="showAbs" tag="div" to="/" class="header-abs">
            <icon class="icon">&#xe624;</icon>
        </router-link>
        <div class="header-fixed" :style="opcityStyle" v-show="!showAbs">
            景点详情
            <router-link to='/'><icon class="header-fixed-back">&#xe624;</icon></router-link>
        </div>
    </div>
</template>

<script>
import icon from "icon/icon";
export default {
  name: "DetailHeader",
  components: {
    icon
  },
  data() {
    return {
      showAbs: true,
      opcityStyle: {
        opacity: 0
      }
    };
  },
  methods: {
    Scroll() {
      const scrollTop = document.documentElement.scrollTop;
      if (scrollTop > 60) {
        let opacity = scrollTop / 140;
        opacity = opacity > 1 ? 1 : opacity;
        this.$set(this.opcityStyle, "opacity", opacity);
        this.showAbs = false;
      } else {
        this.showAbs = true;
      }
    }
  },
  //绑定
  activated() {
    window.addEventListener("scroll", this.Scroll);
  },
  deactivated() {
      window.removeEventListener("scroll", this.Scroll);
  },
};
</script>

<style lang="stylus" scoped>
@import '~styles/varibles.styl';

.header-abs {
    position: absolute;
    left: 0.2rem;
    top: 0.2rem;
    width: 0.8rem;
    height: 0.8rem;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.8);
    text-align: center;
}

.icon {
    font-size: 0.4rem;
    color: #ffffff;
    line-height: 0.8rem;
}

.header-fixed {
    height: $headerHeight;
    line-height: $headerHeight;
    text-align: center;
    overflow: hidden;
    color: #fff;
    background: $bgColor;
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    z-index: 99;
}

.header-fixed-back {
    width: 0.64rem;
    position: absolute;
    text-align: center;
    font-size: 0.4rem;
    top: 0;
    left: 0;
    color: #ffffff;
}
</style>